n=int(input())
rank=[0]*20
for i in range(n):
    for j in range(20):
        p,k=map(int,input().split())
        if p==1:
            p=12
        elif p==2:
            p=9
        elif p==3:
            p=7
        elif p==4:
            p=5
        elif p==5:
            p=4
        elif p==6 or p==7:
            p=3
        elif 8<=p<=10:
            p=2
        elif 11<=p<=15:
            p=1
        else:
            p=0
        rank[j]+=(p+k)
for i in range(20):
    print(i+1,rank[
        i])